<template>
  <!-- 薪酬管理--新增和编辑 -->
  <el-dialog title="驳回理由"
             class="add"
             width="20%"
             :close-on-click-modal="false"
             :visible.sync="visible">
    <el-input type="textarea"
              :autosize="{ minRows: 3, maxRows: 4}"
              placeholder="请输入内容"
              v-model="msg">
    </el-input>
    <!-- 具体表单 -->
    <span slot="footer"
          class="dialog-footer">
      <el-button type="primary"
                 @click="audit">发送</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data () {
    return {
      workerIdVisb: true,
      // 隐藏
      visible: false,
      msg: '',
      id: '',
      isPass: ''
    }
  },
  methods: {
    auditInit (id, isPass) {
      this.msg = ''
      this.id = id
      this.isPass = isPass
    },
    async audit () {
      await this.$http({
        url: this.$http.adornUrl('/task/name-list/audit'),
        method: 'get',
        params: this.$http.adornParams({
          id: this.id,
          isPass: this.isPass,
          message: this.msg
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
        } else {
          this.$message.error(data.msg)
        }
      })
    },
    // 父调用的方法
    addInit () {
      this.visible = true
    },
    init (id) {
      this.dataForm.id = id || 0
      this.visible = true
      this.$http({
        url: this.$http.adornUrl('/sys/salary/info/' + this.dataForm.id),
        method: 'get',
        params: this.$http.adornParams()
      }).then(({ data }) => {
        this.dataForm = data.sysSalary
      })
    },
    // 修改
    update () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl('/sys/salary/update'),
            method: 'post',
            data: this.$http.adornParams(this.dataForm)
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      })
    },
    // 新增
    // /sys/bill/save
    addSave () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl('/sys/salary/save'),
            method: 'post',
            data: this.$http.adornParams(this.dataForm)
          }).then(({ data }) => {
            // console.log(data)
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  // 成功之后的回调
                  this.$emit('refreshDataList')
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      })
    }
    // 结束
  }
}
</script>

<style lang="scss">
.add {
  .el-dialog {
    overflow: hidden;
    border-radius: 5px;
  }
  .el-input.el-input--medium {
    width: 370px;
  }
  .el-dialog__header {
    background-color: #f8f8f8;
  }
  .el-dialog__body {
    display: flex;
    justify-content: center;
  }
  .btn {
    width: 370px;
  }
  .dialog-footer {
    // text-align: center !important;
    padding-bottom: 39px;
  }
  // .el-dialog__footer {
  //   text-align: center;
  //   padding-bottom: 39px;
  // }
}
</style>
